package com.pactera.jep.service.yapin.loan.controller;

import com.pactera.jep.orm.Filter;
import com.pactera.jep.orm.Order;
import com.pactera.jep.orm.Page;
import com.pactera.jep.service.yapin.loan.model.Loan;
import com.pactera.jep.service.yapin.loan.service.LoanService;
import com.pactera.jep.web.controller.CrudController;
import com.pactera.jep.web.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 *
 * @Author YouName
 * @Date Aug 5, 2020 4:18:56 PM
 */
@RestController
@RequestMapping("/loan")
@Api(description = "关联贷款信息表")
public class LoanController extends CrudController<Loan> {

    @Autowired
    LoanService loanService;

    @GetMapping("/{id}")
    @ApiOperation("查询关联贷款信息表")
    public Result get(@PathVariable("id") String id) {
        return Result.success(loanService.get(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除关联贷款信息表")
    public Result delete(@PathVariable("id") String id) {
        return Result.success(loanService.deleteByPrimaryKey(id));
    }

    @PostMapping("/save")
    @ApiOperation("插入关联贷款信息表")
    public Result insert(@RequestBody Loan loan) {
        return Result.success(loanService.insert(loan));
    }

    @PostMapping("/update")
    @ApiOperation("更新关联贷款信息表")
    public Result update(@RequestBody Loan loan) {
        return Result.success(loanService.update(loan));
    }

    /**
     * 为列表页面做数据准备
     */
    @Override
    protected void prepareQuery(Page<Loan> page, List<Filter> filters, List<Order> orders, HttpServletRequest    request) {
        loanService.query(page, filters, orders);
    }
}
